<?php

namespace App\Http\Helpers;

use Illuminate\Support\Facades\Auth;
use phpDocumentor\Reflection\Types\Boolean;

trait AuthHelper
{
    /**
     * 判断是否为系统管理员权限
     * @return bool
     */
    public function isAdmin () : bool
    {
        return Auth::guard('api')->user()->level == 0;
    }

    /**
     * 判断当前用户是否为目标用户本身
     * @param $user_id
     * @return bool
     */
    public function isSelf ($user_id) : bool
    {
        return Auth::guard('api')->user()->id == $user_id;
    }

    /**
     * 判断是否为所有权用户或者系统管理员用户
     * @param $user_id
     * @return bool
     */
    public function isAdminOrSelf ($user_id) : bool
    {
        return $this->isAdmin() || $this->isSelf($user_id);
    }

    /**
     * 获取用户id信息
     * @return int
     */
    public function getUserId () : int
    {
        return Auth::guard('api')->user()->id;
    }

    /**
     * 获取用户信息
     * @return
     */
    public function getUserInfo ()
    {
        return Auth::guard('api')->user();
    }
}
